package com.jd.ty.web.util;


import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.struts2.util.StrutsTypeConverter;

public class DoubleConverter extends StrutsTypeConverter {
	private Logger logger=Logger.getLogger(DoubleConverter.class);
	@Override
	public Object convertFromString(Map context, String[] values, Class toClass) {

		if (Double.class == toClass) {
			String doubleStr = values[0];
			logger.debug("获取到的字符串" + doubleStr);
			if(doubleStr==null||"".equals(doubleStr))
				return new Double(0);
			Double d = Double.parseDouble(doubleStr);
			return d;
		}
		return new Double(0);
	}

	@Override
	public String convertToString(Map context, Object o) {
		logger.debug(" value =" + o+" instanceof= "+(o instanceof Double));
		if(o!=null){
			return o.toString();
		}else{
			return "";
		}
	}

}
